jQuery(document).ready(function() {

    jQuery("#select_country").change(function() {
        var myTag = jQuery('option:selected', this).attr('countryid');
        var url_ajax = jQuery("#url_ajax").val();
        $.post(url_ajax, {id_country: myTag}, function(data) {
            jQuery('#div_get_state').html(data);
        });
    });

    /* check email exist when update profile*/
    jQuery('#txt_email2').keyup(function() {
        var url_ajax = jQuery("#url_ajax").val();
        var email = jQuery(this).val();

        if (email == "") {
            document.getElementById('error_email').innerHTML = "Please fill in your Email";
        }
        else if (validateEmail(email) == false) {
            document.getElementById('error_email').innerHTML = "Email is not a valid e-mail address";
        }
        else {


            jQuery.post(url_ajax, {emailexist2: email}, function(data) {
                //alert(data);
                if (data == 1)
                {
                    jQuery('#error_email').html("Email have already exist");

                }
                else
                {
                    jQuery('#error_email').html("");
                }

            });

        }
    });
    jQuery('#subscribe-email').click(function() {
        var login = jQuery(this).attr('login');
        if (login) {
            jQuery('.progress-img').show();
            jQuery.post(templateUrl + '/ajax/subscribe.php', {email: emailLogin}, function(result) {
                jQuery('.progress-img').hide();
                jQuery('.status-subscribe').html('<div class="alert alert-success">Subscibed Successfully</div>');
            });

        } else {
            jQuery('.status-subscribe').html('<div class="alert alert-danger">Please login to subscribe your email</div>');
        }
    });

    jQuery('#subscribe-email').click(function() {
        var login = jQuery(this).attr('login');
        if (login) {
            jQuery('.progress-img').show();
            jQuery.post(templateUrl + '/ajax/subscribe.php', {email: emailLogin}, function(result) {
                jQuery('.progress-img').hide();
                jQuery('.status-subscribe').html('<div class="alert alert-success">Subscibed Successfully</div>');
            });

        } else {
            jQuery('.status-subscribe').html('<div class="alert alert-danger">Please login to subscribe your email</div>');
        }
    });

    jQuery('#bt_loginpopupbackcome').click(function() {
        jQuery('#booking-false').modal();
        jQuery('#booking-false_register').modal('hide');
    });

    /**
     * 
     */
    jQuery('.request-deal-flight-btn_fight_option').click(function(){
        
           
        var allow_submit = 1;
        var name = jQuery('.full-name-request-deal-flight').val();

        if (name == "")
        {
            jQuery(".error-name-deal-booking").html('Name must not be blank');
            allow_submit = 0;
        }
        else
        {
            jQuery(".error-name-deal-booking").html('');

        }
        var email = jQuery('.email-deal-request-deal-flight').val();
        if (email == "") {

            jQuery(".error-email-deal-booking").html('Email must not be blank');
            allow_submit = 0;
        }
        else
        {
            var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
            if (!re.test(email)) {

                jQuery(".error-email-deal-booking").html('Email is not correct');
                 allow_submit = 0;
            }
            else
            {
                jQuery(".error-email-deal-booking").html('');

            }
        }
        var phone = jQuery('#phone-deal-request-deal-flight').val();
        if(phone == ""){
            
            jQuery('.error-phone-deal-booking').html('Phone must not be blank');
             allow_submit = 0;
        }
        else{
           
            jQuery('.error-phone-deal-booking').html('');
        }
        
        var idFlight = jQuery('#id-deal-flight').val();
        
       
        jQuery.post(templateUrl + '/ajax/request_deal_flight.php',{fullName: name, email: email,phone: phone, idFlight: idFlight}, function(data) {
            

              jQuery('#request-deal-flight-form').modal('hide');
                 
              jQuery('#booking-success').modal();

         });
         
         
        
        
    });
    
    jQuery('.request-deal-flight-btn').click(function() {
        
        var allow_submit = 1;
        var name = jQuery('.full-name-request-deal-flight').val();

        if (name == "")
        {
            jQuery(".error-name-deal-booking").html('Name must not be blank');
            allow_submit = 0;
        }
        else
        {
            jQuery(".error-name-deal-booking").html('');

        }
        var email = jQuery('.email-deal-request-deal-flight').val();
        if (email == "") {

            jQuery(".error-email-deal-booking").html('Email must not be blank');
            allow_submit = 0;
        }
        else
        {
            var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
            if (!re.test(email)) {
                jQuery(".error-email-deal-booking").html('Email is not correct');
                 allow_submit = 0;
            }
            else
            {
                jQuery(".error-email-deal-booking").html('');

            }

        }
        var phone = jQuery('#phone-deal-request-deal-flight').val();
        if(phone == ""){
            
            jQuery('.error-phone-deal-booking').html('Phone must not be blank');
             allow_submit = 0;
        }
        else{
           
            jQuery('.error-phone-deal-booking').html('');
        }
        
	var address = jQuery('#address-deal-request-deal-flight').val();
        if(address == ""){
            
            jQuery('.error-address-deal-booking').html('Address must not be blank');
             allow_submit = 0;
        }
        else{
           
            jQuery('.error-address-deal-booking').html('');
        }
	
        var idDealFlight = jQuery('#id-deal-flight').val();
        

        jQuery.post(templateUrl + '/ajax/request_deal_flight.php',{fullName: name, email: email,phone: phone, 
	    idDealFlight: idDealFlight, address: address}, function(data) {

                 jQuery('#request-deal-flight-form').modal('hide');
                 jQuery('#booking-success').modal();

         });
     
    });
});